<?php

$loader->requireOnce('includes/SearchingCore/ISearchResultView.class.php');

/**
 * Search Result UI
 * @package local.includes.SearchingCore
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class LabSearchResultView implements ISearchResultView {	
	private $logger ;
	
	function __construct() {	    
		$this->logger = LoggerManager::getLogger('local.includes.SearchingCore.LabSearchResultView');
	}	
	
    function renderSearchResult($searchResult = array()) {        
        $html = '<table cellspacing="0" cellpadding="0" class="grid" style="width: 100%">';
        $html .= '<thead>';
        $html .= '<tr>';
        $html .= '<th width="7%">' . L10nHelper::_("ID") . '</th>';
        $html .= '<th width="15%">' . L10nHelper::_("Name") . '</th>';
        $html .= '<th width="9%">' . L10nHelper::_("DOB") . '</th>';        
        $html .= '<th width="7%">' . L10nHelper::_("Gender") . '</th>';
        $html .= '<th width="10%">' . L10nHelper::_("Phone") . '</th>';
        $html .= '<th width="25%">' . L10nHelper::_("Address") . '</th>';
        $html .= '<th width="17%">' . L10nHelper::_("Assignment") . '</th>';
        $html .= '<th>&nbsp;</th>';
        $html .= '</tr>';
        $html .= '</thead>';        
        $html .= '<tbody>';
        
        foreach ($searchResult as $item) {
        
            $html .= '<tr>';            
            $html .= '<td>' . $item->getPatientCode() . '</td>';
            $html .= '<td>' . $item->getPatientName() . '</td>';            
            $html .= '<td>' . $item->getPatientDOB() . '</td>';
            $html .= '<td>' . $item->getGender() . '</td>';
            $html .= '<td>' . $item->getPatientPhone() . '</td>';
            $html .= '<td>' . $item->getPatientAddress() . '</td>';
            $html .= '<td>' . $this->buildAssignmentSelect($item) . '</td>';
            $html .= '<td>';
            $html .= '<input type="button" value="' . L10nHelper::_("View") . '"/>';
            $html .= '&nbsp;';
            $html .= '&nbsp;';
            $html .= '<input type="button" value="' . L10nHelper::_("Print") . '"/>';            
            $html .= '</tr>';
        }
        $html .= '</tbody>';
         
        return $html;
        
    }
    
    private function buildAssignmentSelect($searchResultItem) {
        $assignments = $searchResultItem->getAssignments();
        $html = '<select style="width: 100%">';
        foreach ($assignments as $item) {
        	$html .= "<option>";
        	$html .= $item['request_time'];
        	$html .= "</option>";
        }    
        $html .= "</select>";    
        return $html;
    }
}
?>